﻿using ERP.ERPModels.Production.ShiftManagement;
using ERP.MasterData.Dtos;
using IdentityModel.OidcClient;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace ERP.Web.Controllers
{
    public class ShiftCalendarController : Controller
    {
        private readonly IRepository<ShiftScheduleModel,int> _shiftsScheduleRepository;

        public ShiftCalendarController(IRepository<ShiftScheduleModel, int> shiftsScheduleRepository)
        {
            _shiftsScheduleRepository = shiftsScheduleRepository;
        }

        public IActionResult ShiftCalendarIndex()
        {
            return View();
        }

        [HttpGet]
        public async Task<IActionResult> GetShiftScheduleModelList(ShiftScheduleModelListDTO param)
        {
            var list = await _shiftsScheduleRepository.ToListAsync();

            if (!string.IsNullOrEmpty(param.TeamName))
            {
                list = list.Where(e => e.TeamName == param.TeamName).ToList();
            }

            return Json(new
            {
                code = 0,
                msg = "",
                data = list
            });
        }
    }
}
